export function formatTimeDifference(timestamp) {
    const now = new Date().getTime();
    const diff = Math.floor((now - timestamp) / 1000); // 计算秒数差

    const minutes = Math.floor(diff / 60);
    const hours = Math.floor(minutes / 60);
    const days = Math.floor(hours / 24);
    const months = Math.floor(days / 30); // 假设一个月30天

    if (diff < 60) {
        return '1分钟前更新';
    } else if (minutes < 60) {
        return `${minutes}分钟前更新`;
    } else if (hours < 24) {
        return `${hours}小时前更新`;
    } else if (days < 30) {
        return `${days}天前更新`;
    } else if (months < 3) {
        return `${months}个月前更新`;
    } else {
        return `3月未更（断更）`;
    }
}

// 示例用法
console.log(formatTimeDifference(new Date().getTime() - 50 * 1000)); // 输出: 1分钟
console.log(formatTimeDifference(new Date().getTime() - 3500 * 1000)); // 输出: 58分钟
console.log(formatTimeDifference(new Date().getTime() - 2 * 60 * 60 * 1000)); // 输出: 2小时
console.log(formatTimeDifference(new Date().getTime() - 2 * 24 * 60 * 60 * 1000)); // 输出: 2天
console.log(formatTimeDifference(new Date().getTime() - 35 * 24 * 60 * 60 * 1000)); // 输出: 1个月
console.log(formatTimeDifference(new Date().getTime() - 100 * 24 * 60 * 60 * 1000)); // 输出: null

export function gotoHome(){
	uni.showModal({
		title:"提示",
		content:"页面有误将返回首页",
		showCancel:false,
		success: (res) => {
			if(res.confirm){
				uni.reLaunch({
					url:"/pages/index/index"
				})
			}
		}
	})
}